package com.ape.controller;

import com.ape.bean.PageResponse;
import com.ape.bean.ResultData;
import com.ape.entity.po.SysUserPo;
import com.ape.entity.req.PageSysUserReq;
import com.ape.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * (SysUser)表控制层
 *
 * @author makejava
 * @since 2023-12-04 20:36:38
 */
@RestController
@RequestMapping("/sysUser")
@Api(tags = "系统用户Controller")
public class SysUserController {
    /**
     * 服务对象
     */
    @Autowired
    private SysUserService sysUserService;

    /**
     * 分页查询
     *
     * @param pageSysUserReq 筛选条件
     * @return 查询结果
     */
    @ApiOperation(value = "用户分页查询",notes = "用户数据")
    @GetMapping("/getPage")
    public ResultData<PageResponse<SysUserPo>> queryByPage(@RequestBody PageSysUserReq pageSysUserReq) {
        return ResultData.ok(this.sysUserService.queryByPage(pageSysUserReq));
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResultData<SysUserPo> queryById(@PathVariable("id") Long id) {
        return ResultData.ok(this.sysUserService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysUser 实体
     * @return 新增结果
     */
    @PostMapping
    public ResultData<SysUserPo> add(SysUserPo sysUser) {
        return ResultData.ok(this.sysUserService.insert(sysUser));
    }

    /**
     * 编辑数据
     *
     * @param sysUser 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResultData<SysUserPo> edit(SysUserPo sysUser) {
        return ResultData.ok(this.sysUserService.update(sysUser));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResultData<Boolean> deleteById(Long id) {
        return ResultData.ok(this.sysUserService.deleteById(id));
    }

}

